import config from "../config/config";

// const token = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI2ZmVkMjk5YWUzMDc0YmYwYjJiZmQ1NzljY2UzMWNmZCIsInN1YiI6IjEzIiwiaXNzIjoic2ciLCJpYXQiOjE2NzQ2NTY5MDMsImV4cCI6MTY3NjczMDUwM30.atZQoxnk9_Uh75UHvVt_cZAiI-LED6QnzXx8jFTRfGE"

const http = {
    get (url, params, options = {}) {
        return new Promise((resolve, reject) => {
            uni.request({
                url: config.baseUrl + url,
                method: 'GET',
                data: params,
                success (res) {
                    resolve(res)
                },
                fail (res) {
                    reject(res)
                },
				header:{
					token:uni.getStorageSync('token')
				},
                ...options
            })
        })
    },
    post (url, params, options = {}) {
        return new Promise((resolve, reject) => {
            uni.request({
                url: config.baseUrl + url,
                method: 'POST',
                data: params,
                success (res) {
                    resolve(res)
                },
                fail (res) {
                    reject(res)
                },
				header:{
					token:uni.getStorageSync('token')
				},
                ...options
            })
        })
    },
	put (url, params, options = {}) {
	    return new Promise((resolve, reject) => {
	        uni.request({
	            url: config.baseUrl + url,
	            method: 'PUT',
	            data: params,
	            success (res) {
	                resolve(res)
	            },
	            fail (res) {
	                reject(res)
	            },
				header:{
					token:uni.getStorageSync('token')
				},
	            ...options
	        })
	    })
	},
	delete (url, params, options = {}) {
	    return new Promise((resolve, reject) => {
	        uni.request({
	            url: config.baseUrl + url,
	            method: 'DELETE',
	            data: params,
	            success (res) {
	                resolve(res)
	            },
	            fail (res) {
	                reject(res)
	            },
				header:{
					token:uni.getStorageSync('token')
				},
	            ...options
	        })
	    })
	}
	
}
export default http
